define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/emailinform/index',
                    add_url: 'user/emailinform/add',
                    edit_url: 'user/emailinform/edit',
                    del_url: 'user/emailinform/del',
                    multi_url: 'user/emailinform/multi',
                    table: 'user_email_inform',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {field: 'instoragesucc', title: __('Instoragesucc'), formatter: Table.api.formatter.toggle},
                        {field: 'instoragefail', title: __('Instoragefail'), formatter: Table.api.formatter.toggle},
                        {field: 'outstoragesucc', title: __('Outstoragesucc'), formatter: Table.api.formatter.toggle},
                        {field: 'outstoragefail', title: __('Outstoragefail'), formatter: Table.api.formatter.toggle},
                        {field: 'email', title: __('Email'),formatter: Controller.api.formatter.tests}
                        ]
                ],
                commonSearch: false,
                search:false,
                showToggle: false,
                showColumns: false,
                showExport: false,
                pagination:false
            });

            $(document).on("click", "#saveEmail", function () {

                var address = $("#address").val();
                var id = $("#emailId").val();
                var url = "user/Emailinform/saveEmail?ids="+id+"&email="+address;
                Fast.api.ajax(url);

            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                tests: function (value, row, index) {
                    return '<input type="hidden" id="emailId" value='+row.id+'><input id="address" value='+value+'><button id="saveEmail">保存邮箱</button>';
                }
            }
        }
    };
    return Controller;
});